package org.safaproject.server.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.safaproject.server.model.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor=Exception.class)
public class TagDAO extends HibernateDaoSupport{
	
	@Autowired
	public void initSessionFactory(SessionFactory factory) {
	    setSessionFactory(factory);
	}
	
	public Tag getTagById(Long idTag){
		return (Tag) super.getHibernateTemplate().load(Tag.class, idTag);
	}
	
	@SuppressWarnings("unchecked")
	public List<Tag> getAllTags(){
		return super.getHibernateTemplate().find("from Tag");
	}
	
	public Long saveTag(Tag tag){
		super.getHibernateTemplate().save(tag);
		return tag.getIdTag();
	}
	
	public Long updateTag(Tag tag){
		super.getHibernateTemplate().update(tag);
		return tag.getIdTag();
	}

}
